﻿'===================================================================================
'功能說明:管理頁面名稱,querystring 的設定需注意若是同一個URL中的設定需要一致,否則會授權錯誤.2011/3/8目前提供繁中,簡體,英文等3種語文的頁面名稱設定
'建立人員: andy
'建立日期：2011/1/31
''===================================================================================

Partial Class WebForm_Manage_MenuMaintain

    Inherits BasePage

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            hiUID.Value = ActualUID
            hiDBName.Value = dbName
            '檢查權限'查詢
            If Not ChkProgramRight(1) Then
                gvMenu.Visible = False
            End If
            '新增一筆空白資料
            If Not ChkProgramRight(2) Then
                btnInsert.Visible = False
            End If
            '編輯
            If Not ChkProgramRight(3) Then
                gvMenu.Columns(0).Visible = False
                gvMenuRights.Columns(0).Visible = False


            End If
        End If


    End Sub

    Protected Sub gvMenu_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles gvMenu.RowUpdating
        '存檔,因為無法抓到相關的值,所以用程式來做
        Dim bbl As OAMS.BBL.MenuBBL = New OAMS.BBL.MenuBBL()
        Dim ProgramID As Integer = Integer.Parse(gvMenu.Rows(e.RowIndex).Cells(1).Text)
        Dim RootName As String = CType(gvMenu.Rows(e.RowIndex).FindControl("txtRootName"), TextBox).Text
        Dim Name As String = CType(gvMenu.Rows(e.RowIndex).FindControl("txtName"), TextBox).Text
        Dim NeedControl As Boolean = CType(gvMenu.Rows(e.RowIndex).FindControl("cbNeedControl"), CheckBox).Checked
        Dim URL As String = CType(gvMenu.Rows(e.RowIndex).FindControl("txtURL"), TextBox).Text
        Dim GroupID As String = CType(gvMenu.Rows(e.RowIndex).FindControl("ddlGroupID"), DropDownList).SelectedValue
        Dim QueryStringYN As Boolean = CType(gvMenu.Rows(e.RowIndex).FindControl("cbQueryString"), CheckBox).Checked
        Dim ChnName As String = CType(gvMenu.Rows(e.RowIndex).FindControl("txtChnName"), TextBox).Text
        Dim EngName As String = CType(gvMenu.Rows(e.RowIndex).FindControl("txtEngName"), TextBox).Text
        Dim IsMenu As Boolean = CType(gvMenu.Rows(e.RowIndex).FindControl("cbIsMenu"), CheckBox).Checked
        bbl.UpdateMenu(ProgramID, RootName, Name, NeedControl, URL, GroupID, hiUID.Value, QueryStringYN, dbName, ChnName, EngName, IsMenu)
        e.Cancel = True
        gvMenu.EditIndex = -1 '取消編輯模式
        gvMenu.DataBind()
    End Sub

    Protected Sub btnInsert_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnInsert.Click
        '新增一筆空白資料
        Dim bbl As OAMS.BBL.MenuBBL = New OAMS.BBL.MenuBBL()
        bbl.INSERT_NewOne("", "", True, "", "", hiUID.Value, dbName)
        gvMenu.PageIndex = 0
        gvMenu.EditIndex = 0
        gvMenu.DataBind()
    End Sub

    
    Protected Sub gvMenu_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles gvMenu.RowCommand
        If e.CommandName = "Select" Then '選定
            gvMenu.EditIndex = -1 '取消編輯模式
            gvMenuRights.Visible = True
        End If
        If e.CommandName = "Edit" Then
            gvMenuRights.Visible = False '右半方資料才秀出
        End If
    End Sub

    Protected Sub gvMenu_RowEditing(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewEditEventArgs) Handles gvMenu.RowEditing
        gvMenu.SelectedIndex = -1 '取消
    End Sub
End Class
